package com.flyqiu.flow.model.entity.base;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.flyqiu.common.mybaits.plus.type.MyBaitsFastJson2ObjectHandler;
import com.flyqiu.common.user.FlyQiuUser;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

@EqualsAndHashCode(callSuper = true)
@Data
public class Task extends FlowBaseDao {
    /**
     * 父级任务id
     */
    @TableField("PARENT_TASK_ID_")
    private String parentTaskId;
    /**
     * 流程实例id
     */
    @TableField("PROC_INST_ID_")
    private String procInstId;
    /**
     * 流程发布定义key
     */
    @TableField("PROC_DEPLOY_DEF_KEY_")
    private String procDeployDefKey;
    /**
     * 流程发布定义id
     */
    @TableField("PROC_DEPLOY_DEF_ID_")
    private String procDeployDefId;
    /**
     * 任务定义key
     */
    @TableField("TASK_DEF_KEY_")
    private String taskDefKey;
    /**
     * 任务定义名称
     */
    @TableField("TASK_DEF_NAME_")
    private String taskDefName;
    /**
     * 活动id
     */
    @TableField("ACT_ID_")
    private String actId;
    /**
     * 办理人
     */
    @TableField("ASSIGNEE_")
    private String assignee;
    /**
     * 办理人key
     */
    @TableField("ASSIGNEE_KEY_")
    private String assigneeKey;
    /**
     * 办理人扩展属性
     */
    @TableField(value = "ASSIGNEE_ATTR_", typeHandler = MyBaitsFastJson2ObjectHandler.class)
    private JSONObject assigneeAttr;
    /**
     * 办理人唯一key
     */
    @TableField("ASSIGNEE_UNIQUE_KEY_")
    private String assigneeUniqueKey;

    /**
     * 办理人昵称
     */
    @TableField("ASSIGNEE_NICK_NAME_")
    private String assigneeNickName;

    /**
     * 任务持有人
     */
    @TableField("OWNER_")
    private String owner;
    /**
     * 任务持有人key
     */
    @TableField("OWNER_KEY_")
    private String ownerKey;
    /**
     * 任务持有人扩展属性
     */
    @TableField(value = "OWNER_ATTR_", typeHandler = MyBaitsFastJson2ObjectHandler.class)
    private JSONObject ownerAttr;
    /**
     * 任务持有人唯一key
     */
    @TableField("OWNER_UNIQUE_KEY_")
    private String ownerUniqueKey;
    /**
     * 任务持有人昵称
     */
    @TableField("OWNER_NICK_NAME_")
    private String ownerNickName;

    /**
     * 任务业务key
     */
    @TableField("TASK_BUSINESS_KEY_")
    private String taskBusinessKey;
    /**
     * 任务业务id
     */
    @TableField("TASK_BUSINESS_ID_")
    private String taskBusinessId;
    /**
     * 当前任务业务参数
     */
    @TableField(value = "TASK_BUSINESS_PARAMS_", typeHandler = MyBaitsFastJson2ObjectHandler.class)
    private JSONObject taskBusinessParams;

    /**
     * 租户id
     */
    @TableField("TENANT_ID_")
    private String tenantId;
    /**
     * 创建时间
     */
    @TableField("CREATE_TIME_")
    private LocalDateTime createTime;


    public static void setTaskAssignee(Task task, FlyQiuUser flyQiuUser) {
        task.setAssignee(flyQiuUser.getId());
        task.setAssigneeKey(flyQiuUser.getUserType());
        task.setAssigneeNickName(flyQiuUser.getNickName());
        task.setAssigneeUniqueKey(flyQiuUser.getUniqueKey());
        task.setAssigneeAttr(flyQiuUser.getUserAttr());
    }

    public static void setTaskOwner(Task task, FlyQiuUser flyQiuUser) {
        task.setOwner(flyQiuUser.getId());
        task.setOwnerKey(flyQiuUser.getUserType());
        task.setOwnerNickName(flyQiuUser.getNickName());
        task.setOwnerUniqueKey(flyQiuUser.getUniqueKey());
        task.setOwnerAttr(flyQiuUser.getUserAttr());
    }

}
